import java.util.Stack;

public class demo {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == '(' || ch == '{' || ch == '['){
                //左括号
                stack.push(ch);
            }else {
                //右括号
                if (stack.empty()){
                    return false;
                }
                char top = stack.peek();
                //此时top是左括号，ch是右括号
                if (ch == ')'&& top =='('|| ch == '}' && top == '{' || ch == ']' && top == '['){
                    stack.pop();
                }else {
                    return false;
                }
            }
        }
        if (stack == null){
            return true;
        }
        return true;
    }

    public boolean isOperation(String s){
        if (s.equals("+") ||s.equals("-") ||s.equals("*") ||s.equals("/") ){
            return true;
        }
        return false;
    }
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(String s : tokens){
            if (!isOperation(s)){
                //数字 字符
                stack.push(Integer.parseInt(s));
            }else {
                //有可能是加减乘除中的一个运算符
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch (s){
                    case "+":
                        stack.push(num1 + num2);
                        break;
                    case "-":
                        stack.push(num1 - num2);
                        break;
                    case "*":
                        stack.push(num1*num2);
                        break;
                    case "/":
                        stack.push(num1/num2);
                }
            }
        }
        return stack.pop();
    }
    public static void main(String[] args) {
        Stack<String> stack = new Stack<>();

    }
}
